﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Rifts.Models.Definitions;

namespace Rifts.Creator
{
	/// <summary>
	/// Interaction logic for SelectClass.xaml
	/// </summary>
	public partial class SelectClass : Page
	{
		public SelectClass()
		{
			InitializeComponent();
			DataContextChanged += SelectClass_DataContextChanged;
		}

		void SelectClass_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
		{
			TypedDataContext.UpdateClassList();
			if (TypedDataContext.Classes.Count == 1)
			{
				TypedDataContext.ApplyClass(TypedDataContext.Classes[0]);
				TypedDataContext.NavigateNextCommand.Execute(null);
			}
		}

		public CreatorViewModel TypedDataContext
		{
			get { return (CreatorViewModel)DataContext; }
		}

		private void Button_Click(object sender, RoutedEventArgs e)
		{
			TypedDataContext.Character.RejectChanges(); //Unwind the picks already made

			var occ = (CharacterClass)((FrameworkElement)sender).DataContext;
			TypedDataContext.ApplyClass(occ);
		}
	}
}
